﻿
var tablePurchasedItemController = function ($scope,$log, $filter, $modal, ngTableParams) {

  

    $scope.headersData = [
        { columnName: "Product #" },
        { columnName: "Description" },
        { columnName: "Price Per Unit" },
        { columnName: "Qty units" },
        { columnName: "Amount" }
    ];

    var data = [
        {index:  '7', description: "Product Sample data",        qtyUnits:2,   pricePerUnit: 450 },
        { index: '6', description: "another Product data",       qtyUnits: 1,   pricePerUnit: 150 },
        {index:  '5', description: "one Sample data",              qtyUnits:4,    pricePerUnit: 40 },
        { index: '4', description: "two Product data",             qtyUnits: 2,   pricePerUnit: 150 },
        {index:  '3', description: "three Sample data",           qtyUnits:1,     pricePerUnit: 150 },
        {index:  '2', description: "4 Sample data",                 qtyUnits:3,     pricePerUnit: 150 },
        { index: '1', description: "Five Product data" ,            qtyUnits: 6,   pricePerUnit: 660 }
    ];


    $scope.editColumName = function () {

      var modalInstance = $modal.open({
          templateUrl: '/App/Templates/change-headers-tempate.html',
          controller: 'tableHeadersDefinitionCtrl',
          size :'lg'
        });

      modalInstance.result.then(function (newHeadersData) {
          $scope.headersData = newHeadersData;
        }, function () {
            $log.info('Modal dismissed at: ' + new Date());
        });

    };



    $scope.tableParams = new ngTableParams({
        page: 1,                                                      // show first page
        count: data.length                                      // count per page no ages I put max items
    }, {        
        total: data.length,                                     // length of data
        getData: function ($defer, params) {
                                                                        // use build-in angular filter
            var orderedData = params.sorting() ?
                $filter('orderBy')(data, params.orderBy()) : $scope.headersData[0].columnName;
                                                                          // Hide the pagination numbers
            params.settings({ counts: data.length > 10 ? [10, 25, 50] : [] });

            $defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
        }
    });
};







